<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        div {
            text-align: center;
            margin: 100px auto 0;
            height: 40px;
        }

        a {
            text-decoration: none;
            list-style: none;
            box-sizing: border-box;
            width: 98px;
            height: 36px;
            line-height: 36px;
            display: inline-block;
            border: 2px solid gray;
            font-size: 20px;


        }

        main {
            margin: auto;
            border: 2px solid gainsboro;
            width: 300px;
            height: 500px;
        }
    </style>
</head>

<body>
    <div>
        <a href="#/home">首页</a>
        <a href="#/service">服务</a>
        <a href="#/personal">个人</a>
    </div>
    <main></main>
</body>

</html>
<script>
    // 用hashchange事件 监听url地址中hash值的变化, 只要hash值发生变化hashchange的回调函数就会执行, 在回调函数内部获取最新的hash值 ( location.hash ) , 使用switch或者if 判断, 根据不同的hash值调用不同的函数, 完成内容的渲染.
    window.onhashchange = function () {
        switch (location.hash) {
            case '#/home': home_page(); break;
            case '#/service': service_page(); break;
            case '#/personal': personal_page(); break;
        }
    }



// 渲染页面
    function home_page() {
        document.querySelector('main').innerHTML = '我是首页'
    }
    function service_page() {
        document.querySelector('main').innerHTML = '我是服务'
    }
    function personal_page() {
        document.querySelector('main').innerHTML = '个人中心'
    }
</script>